<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('主治')" />
    <th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>

                        <!--                            <li class="select-time">
                                                        <label>时间： </label>
                                                        <input type="text" class="time-input" id="startTime" placeholder="查询时间" name="endTime"/>
                                                    </li>-->
                        <li>
                            <label>选择时间： </label>
                            <!--                            <select name="time1" id="time1" onchange="dateSelectInit(this.value)">-->
                            <select name="time1" id="time1" onclick="dateSelectInit(this.value)"  >

                                <!--<option value="week">近一周</option>
                                <option value="month">近一月</option>
                                <option value="3month">近三月</option>-->
                                <option value="">--请选择--</option>
                                <option value="yestoday">昨天</option>
                                <option value="month2">本月</option>
                            </select>
                        </li>
                        <li class="select-time">

                            <label>时间： </label>
<!--                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>-->
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="startTime"/>
                            <span>-</span>
<!--                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>-->
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime"/>


                        </li>
                        <div class="col-sm-4 " style="margin-top: 3px" >
                            <label class="checkbox-inline check-box">
                                <input type="checkbox" value="1" name="p1" id="p1">小票号为空</label>
                            <label class="checkbox-inline check-box">
                                <input type="checkbox" value="1" name="p2" id="p2">金额不等</label>
                        </div>



<!--                       <li>
                            <label class="checkbox-inline check-box">
                                <input type="checkbox" value="1" name="p1">小票号为空</label>
                            <label class="checkbox-inline check-box">
                                <input type="checkbox" value="1" name="p2">金额不等</label>
                       </li>-->

                        <li>
                            <!-- 搜索同时 查询统计信息 -->
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search() ; queryList2()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset() ;resetCheckBox() "><i class="fa fa-refresh"></i>&nbsp;重置</a>

                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--            <a class="btn btn-success" onclick="$.operate.add()" >
                            <i class="fa fa-plus"></i> 新增
                        </a>
                        <a class="btn btn-success" onclick="link()" >
                            <i class="fa"></i> 新增药品关系
                        </a>
                        <a class="btn btn-success" onclick="recommend()" >
                            <i class="fa"></i> 新增为推荐
                        </a>
                        <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:post:edit">
                            <i class="fa fa-edit"></i> 修改
                        </a>
                        <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:post:remove">
                            <i class="fa fa-remove"></i> 删除
                        </a>-->
            <!--            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:post:export">
                            <i class="fa fa-download"></i> 导出
                        </a>-->

<!--            <a class="btn btn-info" onclick="$.table.importExcel()" >
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()">
                <i class="fa fa-download"></i> 导出
            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <div>
<!--                <span><h3 id="01"></h3></span>-->
                <span><p id="01"></p></span>
            </div>
            <table id="bootstrap-table"></table>
        </div>
    </div>
    <!--    <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="post-form1">
                    <div class="select-list">
                        <ul>
                            <li>
                                药品信息：<input type="text" name="plucode" th:placeholder="店内码或拼音码"/>
                            </li>
                            &lt;!&ndash;                        <li>
                                                        客户名称：<input type="text" name="companyName"/>
                                                    </li>&ndash;&gt;
                            &lt;!&ndash;  <li>
                                  岗位状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                                  <option value="">所有</option>
                                  <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                              </select>
                              </li>&ndash;&gt;
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>-->

    <!--        <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" >
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:post:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:post:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:post:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>-->

    <!--        <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table1"></table>
            </div>-->
</div>
</div>


<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-editable-js" />
<th:block th:include="include :: bootstrap-table-export-js" />
<!-- 日期工具插件  -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ==" crossorigin="anonymous"></script>
<script >
    var ctx = "[[@{/}]]";
    // 时间选择框 初始化
    function  dateSelectInit(flag) {
        // week 近一周 month 近一月  3month 近3月
        if (flag == 'week'){
            $("#startTime").val(getLastWeek().last);
            $("#endTime").val(getLastWeek().now);
        }
        if(flag == 'month'){
            $("#startTime").val(getLastMonth().last);
            $("#endTime").val(getLastMonth().now);
        }
        if(flag == '3month'){
            $("#startTime").val(getLast3Month().last);
            $("#endTime").val(getLast3Month().now);
        }

        // 待选择时 清空输入框
        if(flag == ''){
            $("#startTime").val('');
            $("#endTime").val('');
        }

        // 昨天
        if(flag == 'yestoday'){

            // 获取 昨天 日期
           console.log( "昨天日期： " + moment().add(-1,'days') );
            $("#startTime").val(moment().subtract(1,'day').format('YYYY-MM-DD'));
            $("#endTime").val(moment().subtract(1,'day').format('YYYY-MM-DD'));
        }

        // 本月

        if(flag == 'month2'){
            $("#startTime").val(moment().startOf('month').format('YYYY-MM-DD'));
            $("#endTime").val(moment().format('YYYY-MM-DD'));
        }
    }
</script>
<script th:inline="javascript">
    //  var editFlag = [[${@permission.hasPermi('system:post:edit')}]];
    // var removeFlag = [[${@permission.hasPermi('system:post:remove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "baodao/pay";

    function queryList2(){
        $("#01").html('')
        var apiUrl = prefix + "/list2";
        // 参数
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();

        console.log("查询 list2" + apiUrl);
        $.ajax({
            type: 'POST',
            //    url: ctx + '/queryAmount',
            //    url:   'http://localhost:8005/baodao/pay/queryAmount',
            url:   apiUrl,
            data: {startTime:startTime,endTime:endTime},
            success: function (result) {
                console.log(result)
                //填充数据
               /* $("#total_fee").text(result.total_fee  + ' 元');
                $("#receipt_fee").text(result.receipt_fee  + ' 元');
                $("#coupon_fee").text(result.coupon_fee  + ' 元');*/
               console.log(result.total_fee);
               console.log(result.receipt_fee);
               console.log(result.coupon_fee);
                if(result.data != null) {
                    $("#01").html("  &nbsp 总金额:" + result.data.total_fee + "   &nbsp &nbsp &nbsp 实收金额:" + result.data.receipt_fee + "   &nbsp &nbsp &nbsp 折扣金额:" + result.data.coupon_fee);
                }
              /* $("#02").html(result.receipt_fee);
               $("#03").html(result.coupon_fee);*/



            },
            dataType: 'json'
        });


    }


    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: ctx + 'baodao/goodszz' + "/export",
            importTemplateUrl: ctx + 'baodao/goodszz' + "/importTemplate",
            importUrl: ctx + 'baodao/goodszz' + "/importData",
            /*  sortName: "companyId",*/
            modalName: "药品主治",
            // 测试父子表
            detailView: false,
            clickEdit:true,
            onEditableSave: onEditableSave,
            // showExport: true,  //导出
            // 测试新增 查询条件
            /* queryParams: function(params) {
                 var curParams = {
                     // 传递参数查询参数
                     pageSize: params.limit,
                     pageNum: params.offset / params.limit + 1,
                     searchValue: params.search,
                     orderByColumn: params.sort,
                     isAsc: params.order,
                     // 新增 flag 为0 展示全部 药品信息，为1 展示药品关联表中已建立关系的药品列表
                     //   flag:  $("#flag").val()
                     flag: 0
                 }
                 return curParams;
             },*/
            columns: [{
                checkbox: true
            },
                {
                    field: 'out_trade_no',
                    title: '终端流水号',
                    width: 100
                },
                {
                    field: 'terminal_id',
                    title: '终端号',
                    width: 100
                },
                {
                    field: 'merchant_name',
                    title: '商户名称',
                    width:160

                },
                {
                    field: 'merchant_no',
                    title: '商户号',
                    width:130
                },

                {
                    field: 'card_type',
                    title: '用户银联卡类型',
                    width:80,
                    align:'center',
                    formatter(value){
                        if(value = '0')
                            return '储蓄卡'
                        else if(value = '1')
                            return '信用卡'
                        else
                            return '未知'
                    }
                },

                {
                    field: 'total_fee',
                    title: '总金额',
                    width: 100,
                    align: 'right',
                    formatter(value){
                        var v1 = value * 0.01;
                        return dealMoney(v1)
                    }
                },
                {
                    field: 'receipt_fee',
                    title: '实收金额',
                    width: 100,
                    align: 'right',
                    formatter(value){
                        var v1 = value * 0.01;
                        return dealMoney(v1)
                    }
                },
                {
                    field: 'coupon_fee',
                    title: '优惠券金额',
                    width: 100,
                    align: 'right',
                    formatter(value){
                        var v1 = value * 0.01;
                        return dealMoney(v1)
                    }
                },
                {
                    field: 'pay_type',
                    title: '支付方式',
                    width: 120,
                    align: 'center',
                    formatter(value){
                        if(value = '010')
                            return '微信';
                        else if(value = '020')
                            return '支付宝';
                        else if(value = '030')
                            return '银行卡';
                        else if(value = '060')
                            return 'QQ钱包';
                        else if(value = '080')
                            return '京东钱包';
                        else if(value = '100')
                            return '翼支付';
                        else if(value = '110')
                            return '银联二维码';

                    }
                },
                {
                    field: 'sell_no',
                    title: '小票号',
                    width: 60,

                },
                {
                    field: 'end_time',
                    title: '支付完成时间',
                    width: 150,

                },
                {
                    title: '操作',
                    align: 'center',
                    width: 50,
                    formatter: function(value, row, index) {
                        var actions = [];
                        /* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');row.sellNo + row.startTime + row.endTime*/
                        actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="queryReceiptDetails(\'' + row.sell_no +"','"+ row.end_time+ "','"+ row.end_time+ '\')"><i class="fa fa-edit"></i>查询</a> ');
                        /* actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        // actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        //actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }


            ],
        };


        $.table.init(options);

        $('#bootstrap-table').on( 'click', 'td:has(.editable)', function (e) {
            //e.preventDefault();
            // console.log("点击单元格")
            e.stopPropagation(); // 阻止事件的冒泡行为
            $(this).find('.editable').editable('show'); // 打开被点击单元格的编辑状态
        } );



    });
</script>

<script>
    // 获得所有选中的数据
    function link() {
        // $.table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        console.log("已选择数据数量：" + rows.length)
        console.log("已选择数据" + rows.toString())
        let id = rows.toString();
        let url = ctx + 'baodao/demo02/add' + '?id=' + id;
        console.log("弹窗 url" + url)
        var result = url.replace(/#/g, '%23');
        $.modal.openTab("新增药品关系",result);
        // 关闭本窗口
        // var index = ctx + '/baodao/demo02';
        $.modal.close(prefix);
    }

   // function dealMoney(money, sysmbol = '¥', places = 2) {
    function dealMoney(money, sysmbol = '', places = 2) {
        const zero = `${sysmbol}0.00`;
        if (isNaN(money) || money === '') return zero;

        if(money && money != null){
            money = `${money}`;
            let left=money.split('.')[0]; // 小数点左边部分
            let right=money.split('.')[1]; // 小数点右边
            // 保留places位小数点，当长度没有到places时，用0补足。
            right = right ? (right.length >= places ? '.' + right.substr(0, places) : '.' + right + '0'.repeat(places - right.length)) : ('.' + '0'.repeat(places));
            var temp = left.split('').reverse().join('').match(/(\d{1,3})/g); // 分割反向转为字符串然后最多3个，最少1个，将匹配的值放进数组返回
            return (Number(money) < 0 ? '-' : '') + sysmbol + temp.join(',').split('').reverse().join('') + right; // 补齐正负号和货币符号，数组转为字符串，通过逗号分隔，再分割（包含逗号也分割）反向转为字符串变回原来的顺序
        } else if (money === 0) {
            return zero;
        } else {
            return zero;
        }
    }

    function queryReceiptDetails(p1,p2,p3) {
        console.log("查询小票明细： " + p1);
        if (p1 == null)
            //alert("小票号为空")
            // {
        {
            $.modal.alertWarning('小票号为空');
           }
        else {
            console.log("弹窗展示交易明细")
            //var url = "http://9.lanchen.iot-m.cn:30010/ticket.html?gtin=" + p1;
          //  var url = "http://localhost:8005/baodao/pay/receiptDetails/"  + p1;
            var url = prefix +"/receiptDetails/"  + p1;
            console.log("跳转页面： " + url)
            console.log("请求连接： " + url)
            $.modal.open('交易明细',url,900,800);
        }
    }

    // 重置 p1 p2 复选框
    function resetCheckBox() {

        // 重置复选框
        console.log("重置复选框")
        $("#p1").parent().removeClass('checked');
        $("#p2").parent().removeClass('checked');

        $("#01").text('')

    }

    /*    function saveData(index, field, value) {
            $("#bootstrap-table").bootstrapTable('updateCell', {
                index: index,       //行索引
                field: field,       //列名
                value: value        //cell值
            })
        }*/

    function onEditableSave (field, row, rowIndex, oldValue, $el) {
        // alert("字段名：" + field + "，当前值：" + row[field]  + "，旧值：" + oldValue );
        // alert("商品码：" + row.goodscode + "，当前值：" + row[field]  + "，旧值：" + oldValue );
        //更新数据库数据

        console.log(field)
        console.log(row)
        console.log(rowIndex)
        console.log(oldValue)
        console.log($el)
        if(field == 'goodsZZ'){
            // 更新主治信息
            if(row[field] != '待补充') {
                $.ajax({
                    type: 'post',
                    url: ctx + 'baodao/goodszz/updateGoodsZZ',  // 获取设备历史温度
                    timeout: 30000,
                    data: {"goodsCode": row.goodscode, "goodsZZ": row[field]},
                    dataType: 'json',
                    success: function (data) {

                        console.log(data);
                    },

                    error: function () {
                        alert("调用数据接口失败");
                    }
                });
            }
        }

        if(field == 'price'){
            // 更新价格信息
            if(row[field] != '待补充') {
                $.ajax({
                    type: 'post',
                    url: ctx + 'baodao/goodszz/updatePrice',  // 获取设备历史温度
                    timeout: 30000,
                    data: {"goodsCode": row.goodscode, "price": row[field]},
                    dataType: 'json',
                    success: function (data) {

                        console.log(data);
                    },

                    error: function () {
                        alert("调用数据接口失败");
                    }
                });
            }
        }



    }

    /*    function recommend() {
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            console.log("已选择数据数量：" + rows.length)
            console.log("已选择数据" + rows.toString())
            let id = rows.toString();
            let url = ctx + 'baodao/demo01/edit' + '?id=' + id;
            console.log("弹窗 url" + url)
            var result = url.replace(/#/g, '%23');
            $.modal.openTab("新增为关联",result);
        }*/
    //初始化子表格(无线循环)
    initSubTable = function (index, row, $detail) {

        function queryParams(){
            let tmp = {"goodsCode":row.goodscode};
            return tmp;
        }
        var parentid = row.id;
        var cur_table = $detail.html('<table></table>').find('table');
        //  var cur_table = $detail.html('<table><title>测试</title></table>').find('table');
        $(cur_table).bootstrapTable({
            url: ctx + 'baodao/demo02/queryGoodsLink',
            method: 'post',
            contentType: 'application/x-www-form-urlencoded',
            queryParams:queryParams(),
            //data: {'goodsCode':'401-01-330'},
            ajaxOptions: { id: parentid },
            uniqueId: "id",
            striped: true, //是否显示行间隔色
            pagination: true,//显示分页
            sidePagination: "client",
            pageNumber:1,
            pageSize: 4,
            pageList: [4, 25],
            columns: [
                {
                    field: '',
                    title: '关联药品'
                },
                {
                    field: 'goodscode',
                    title: '内码'
                },
                {
                    field: 'goodsname',
                    title: '名称'
                },
                {
                    field: 'mfrs',
                    title: '厂商'
                },
                {
                    field: 'norm',
                    title: '规格'
                },
                /*                {
                                    field: 'plucode',
                                    title: '关联药品推荐'
                                },*/

                /*    {
                        field: 'mfrs',
                        title: '生产企业'
                    },
                    {
                        field: 'norm',
                        title: '包装规则'
                    },
                    {
                        field: 'plucode',
                        title: '条码'
                    },*/
            ],
            //无线循环取子表，直到子表里面没有记录
            onExpandRow: function (index, row, $Subdetail) {
                initSubTable(index, row, $Subdetail);
            }
        });
    };


</script>


<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的药品主治数据
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

<script>
    // 近3个月
    function getLast3Month() {
        var now = new Date();
        var year = now.getFullYear();
        var month = now.getMonth() + 1;//0-11表示1-12月
        var day = now.getDate();
        var dateObj = {};

        dateObj.now = year + '-' + month + '-' + day;
        var nowMonthDay = new Date(year, month, 0).getDate();    //当前月的总天数
        if(month - 3 <= 0){ //如果是1、2、3月，年数往前推一年
            var last3MonthDay = new Date((year - 1), (12 - (3 - parseInt(month))), 0).getDate();    //3个月前所在月的总天数
            if(last3MonthDay < day){    //3个月前所在月的总天数小于现在的天日期
                dateObj.last = (year - 1) + '-' + (12 - (3 - month)) + '-' + last3MonthDay;
            }else{
                dateObj.last = (year - 1) + '-' + (12 - (3 - month)) + '-' + day;
            }
        }else{
            var last3MonthDay = new Date(year, (parseInt(month) - 3), 0).getDate();    //3个月前所在月的总天数
            if(last3MonthDay < day){    //3个月前所在月的总天数小于现在的天日期
                if(day < nowMonthDay){        //当前天日期小于当前月总天数,2月份比较特殊的月份
                    dateObj.last = year + '-' + (month - 3) + '-' + (last3MonthDay - (nowMonthDay - day));
                }else{
                    dateObj.last = year + '-' + (month - 3) + '-' + last3MonthDay;
                }
            }else{
                dateObj.last = year + '-' + (month - 3) + '-' + day;
            }
        }
        console.log(dateObj);
        return dateObj;
    }
    // 近一个月
    function getLastMonth() {
        var now = new Date();
        var year = now.getFullYear();
        var month = now.getMonth() + 1;//0-11表示1-12月
        var day = now.getDate();
        var dateObj = {};
        dateObj.now = year + '-' + month + '-' + day;
        var nowMonthDay = new Date(year, month, 0).getDate();    //当前月的总天数
        if(month - 1 <= 0){
            //如果是1月，年数往前推一年　　　　
            dateObj.last = (year - 1) + '-' + 12 + '-' + day;
        }else{
            var lastMonthDay = new Date(year, (parseInt(month) - 1), 0).getDate();
            if(lastMonthDay < day){    //1个月前所在月的总天数小于现在的天日期
                if(day < nowMonthDay){        //当前天日期小于当前月总天数
                    dateObj.last = year + '-' + (month - 1) + '-' + (lastMonthDay - (nowMonthDay - day));
                }else{
                    dateObj.last = year + '-' + (month - 1) + '-' + lastMonthDay;
                }
            }else{
                dateObj.last = year + '-' + (month - 1) + '-' + day;
            }
        }
        console.log(dateObj);
        return dateObj;
    }
    // 近一周
    function getLastWeek() {
        var now = new Date();
        var year = now.getFullYear();
        var month = now.getMonth() + 1;//0-11表示1-12月
        var day = now.getDate();
        var dateObj = {};
        dateObj.now = year + '-' + month + '-' + day;
        if(day - 7 <= 0){   //如果在当月7日之前
            var lastMonthDay = new Date(year, (parseInt(month) - 1), 0).getDate();    //1周前所在月的总天数
            if(month - 1 <= 0){ //如果在当年的1月份
                dateObj.last = (year - 1) + '-' + 12 + '-' + (31 - (7 - day));
            }else{
                dateObj.last = year + '-' + (month - 1) + '-' + (lastMonthDay - (7 - day));
            }
        }else{
            dateObj.last = year + '-' + month + '-' + (day -7);
        }
        console.log(dateObj);

        return dateObj;
    }
    // var dateObj1 = getLast3Month();
    // var dateObj2 = getLastMonth();
    // var dateObj3 = getLastWeek();
    // window.onload = function(){
    //     var last3Month = document.getElementById("last3Month").innerHTML = "近三个月：<br>" + dateObj1.now + '<br>' + dateObj1.last;
    //     var lastMonth = document.getElementById("lastMonth").innerHTML = "近一个月：<br>" + dateObj2.now + '<br>' + dateObj2.last;
    //     var lastWeek = document.getElementById("lastWeek").innerHTML = "近一周：<br>" + dateObj3.now + '<br>' + dateObj3.last;
    // }

</script>
// </script>
</body>
</html>